<%@ page contentType="text/html;charset=UTF-8"%>
<%@include file="../../common/sessionValidate.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
  <head>
    <title>批发商商品copy</title>
    <%@ include file="../../common/meta.jsp"%>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
	<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen"  id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
  </head>
  <style>
	hr {
	    margin-top:1px;
	    border-bottom: 1px solid #1BBC9B;
	}
  </style>
  <body>
  <div class="" style="margin-right:2px;padding-right:1px;">



    <!--------------------------查询条件表格  start------------------------------->
  	<form class="form-horizontal" name="form1" id="form1">
	<!-- 查询面板 -->
	<div class="panel panel-primary" id="cxDiv">
	  <!-- Default panel contents -->
	  <div class="panel-heading  " >
      	<i class='icon-cogs'></i>&nbsp;批发商商品copy
        <span class="text-right pull-right">
        	<button type="button" class=" btn btn-success btn-xs img-rounded"  onclick="saveCopy()"><i class="icon-cog"></i>&nbsp;执行copy</button>&nbsp;
            <button type="reset" class=" btn btn-success btn-xs img-rounded"  > <span class="icon-retweet"></span>&nbsp;重置</button>&nbsp;
            <button type="button" class=" btn btn-success btn-xs img-rounded" id="shButton" >&nbsp;<span id="qhDiv" class="icon-chevron-up"></span>&nbsp;</button>
        </span>
	  </div>
	  <div class="panel-body" id="shDiv" class="panel-collapse collapse in">
	  	 <div class="col-xs-6">
	          <div class="form-group">
	              <label class="control-label col-xs-5">商品从批发商</label>
	              <div class="col-xs-7">
	              	<select  id="from_customer" name="from_customer" onChange="Search1(0)" type="text" class="form-control">
						<option value="">---请选择---</option>
	              	</select>
	              </div>
	          </div>
	      </div>

	      <div class="col-xs-6">
	          <div class="form-group">
	              <label class="control-label col-xs-6">copy至批发商</label>
	              <div class="col-xs-6">
	              	<select  id="to_customer" name="to_customer"  type="text" class="form-control">
						<option value="">---请选择---</option>
	              	</select>
	              </div>
	          </div>
	      </div>

	  </div>
	</div>
    </form>
    <!--------------------------查询条件表格end------------------------------------->

 	<form class="form-horizontal" name="form2" id="form2">
    <!--------------------------信息列表：带表格面板  start--------------------------------->
	<div class="panel panel-primary">
	  <div class="panel-heading clearfix" >
	  	 <i class='icon-reorder'></i>&nbsp; 数据列表
	  	 <span class="text-right pull-right ">
            <!-- <a href="<%=basePath%>t_goods/toT_goodsCurd?oplx=add" class="text-danger"><i class='icon-plus'></i>&nbsp;新增</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="toEdits()" class="text-danger"><i class='icon-pencil'>&nbsp;修改</i></a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="toViews()"  class="text-danger"><i class='icon-table'></i>&nbsp;查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="getDel()" class="text-danger"><i class='icon-minus'></i>&nbsp;删除</a>&nbsp;&nbsp;&nbsp;&nbsp; -->
            <a href="#" onclick="Search(0)" class="text-danger btn-sm"><i class='icon-refresh'></i>&nbsp;刷新</a>&nbsp;&nbsp;
            <a href="#" onclick="showOrHidden()" class="text-danger btn-sm"><span id="fsDiv" class='glyphicon glyphicon-resize-full'></span></a>
	    	<input type="hidden" name="to_customer_id" id="to_customer_id" value="">
	     </span>
	  </div>
	  <div class="panel-body">
	    <p>每页显示<select id="pageSize" class=" label-primary" onchange="Search(0)">
		  <option value="1000" >1000</option>
		 </select>条记录，&nbsp;&nbsp;&nbsp;&nbsp;共有记录：<span id="totalCount" class="label label-primary">0</span> 条，总页数：<span id="totalPageNo" class="label label-primary">0</span>页。
        </p>
	    <table id="grid" class="table table-condensed table-striped table-bordered table-hover" class="sortable" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
	     <thead id="grid_head">
	      <tr>
	          <th onclick="" class="table-checkbox" ><input class="group-checkable" name="batchSelectedAll" id="batchSelectedAll" type="checkbox" onclick="selectAll()"></th>
	          <th onclick="sortTableT.sort('grid',0,'String')">产品id</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">商品名称</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">批发商</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">电话</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">发货价</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">数量</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">上架时间</th>
	      </tr>
	     </thead>
	     <tbody id="grid_body"></tbody>
	    </table>
	    <div class="paging-toolbar">
	   		<ul class="pager" style='margin-bottom:5px;' id='grid_paging'></ul>
	    </div>
	  </div>
    </div>
    <!--------------------------信息列表：带表格面板 end------------------------------------>
	</form>

  </div>
  </body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script src="<%=basePath%>js/jquery-1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js" ></script>
<script src="<%= basePath %>js/calendar.js" ></script>

<script type="text/javascript">
$().ready(function(){
	//1、初始化数据显示
	Search(0);

	//2、隐藏或者显示
    $("#shButton").click(function(){
    	$("#shDiv").toggle();
    	$("#qhDiv").toggleClass("icon-chevron-up icon-chevron-down");
  	});

}) //end funciton read;

//执行copy
function saveCopy(){
	var from_customer = $('#from_customer option:selected').val();//选中的值 //document.getElementById("from_customer").value;
	//alert("from_customer="+from_customer);
	if(from_customer=null||from_customer==""){
		alert("请选择商品批发商！");
		return false;
	}
	var to_customer = $('#to_customer option:selected').val();//选中的值 //document.getElementById("to_customer").value;
	//alert("to_customer="+to_customer);
	if(to_customer=null||to_customer==""){
		alert("请选择商品copy至批发商！");
		return false;
	}

	if(checkfunctionMutlIDS()==true){
		$("#to_customer_id").val($('#to_customer option:selected').val());
		var url = "<%=basePath%>t_goods/pfsT_goodsBatchSave?time="+Math.random();
		form2.action= url;
		//alert(url);
		form2.submit();
	}else{
		alert("请至少选择一条数据进行操作！");
	}
}

//校验多选框,选中多条记录，并返回该记录的id；适用于选择多条记录操作。
function checkfunctionMutlIDS(){
      var obj, count, obj1, checkvalue;
      checkvalue ="";
      obj = document.getElementsByName("batchSelected");
      count=0;
      //alert("obj.length="+obj.length);
      for(i=0;i<obj.length;i++)
      {
    	  //alert("33333");
    	 if(obj[i].checked==true)
         {
         	count++;
         	checkvalue += obj[i].value +";";
         	//var cid =$(obj[i]).val();
         	//alert("选中数据="+checkvalue);
         }
      }
      if(count<1)
      {
         //alert("请至少选择一条资源进行操作！");
         //showWarnTips("请至少选择一条资源进行操作！!", "提示信息：");
         return false;
      }
	  //alert("checkvalue="+checkvalue);
      return true;
}

//根据查询条件，查询列表数据并显示
function Search(startIndex){
	var pageSize = document.getElementById("pageSize").value;
	var from_customer = document.getElementById("from_customer").value;
	//var condition = $("#form1").serialize();
	var url = "<%=basePath%>t_company_reg/getAllT_company_reg?startIndex="+startIndex+"&pageSize="+pageSize+"&time="+Math.random();
	//alert(url);
	$.getJSON(url, function (data){
		//1、表格行内容输出
	    $.each(data.items, function(i,item){
	    	$("#from_customer").append(
					"<option value='"+item.company_id+"'>"
						+ item.company_name
			  + "</option>");
		});//end each data;
	})//end getJSON;
	Search3(0);
}

//根据查询条件，查询列表数据并显示
function Search3(startIndex){
	var pageSize = document.getElementById("pageSize").value;
	var to_customer = document.getElementById("to_customer").value;
	//var condition = $("#form1").serialize();
	var url = "<%=basePath%>t_company_reg/getAllT_company_reg?startIndex="+startIndex+"&pageSize="+pageSize+"&time="+Math.random();
	//alert(url);
	$.getJSON(url, function (data){

		//1、表格行内容输出
	    $.each(data.items, function(i,item){
	    	$("#to_customer").append(
					"<option value='"+item.company_id+"'>"
						+ item.company_name
			  + "</option>");
		});//end each data;

	})//end getJSON;
}

//根据查询条件，查询列表数据并显示
function Search1(startIndex){
	var pageSize = document.getElementById("pageSize").value;
	var from_customer = document.getElementById("from_customer").value;
	//var condition = $("#form1").serialize();
	var url = "<%=basePath%>t_goods/getAllT_goods?startIndex="+startIndex+"&pageSize="+pageSize+"&customer_id="+from_customer+"&time="+Math.random();
	//alert(url);
	$.getJSON(url, function (data){
	//$("#pageSize").html(data.pageSize);
	$("#totalCount").html(data.totalCount);
	$("#totalPageNo").html(data.totalPageNo);
	$("#grid_body").html("");

	//1、表格行内容输出
    $.each(data.items, function(i,item){
		var str="<tr>";
		str+="<td><input class='checkboxes' name='batchSelected' id='batchSelected' type='checkbox' value='"+item.goods_id+"'></td>";
		str+="<td>"+doNull(item.goods_id)+"</td>";
		str+="<td>"+doNull(item.goods_name)+"</td>";
		str+="<td>"+doNull(item.customer_name)+"</td>";
		str+="<td>"+doNull(item.company_name)+"</td>";
		str+="<td>"+doNull(item.price)+"</td>";
		str+="<td>"+doNull(item.num)+"</td>";
		str+="<td>"+doNull(item.creattime)+"</td>";

		//str+="<td>&nbsp;&nbsp;";
		//str+="<a href='<%=basePath%>t_goods/toT_goodsCurd?oplx=copy&id="+item.goods_id+"&time="+Math.random()+"' class='text-danger'>&nbsp;&nbsp;<span class='icon-check' style='color:rgb(0, 128, 255)'>复制</span>&nbsp;&nbsp;</a>";
		//str+="<a href='<%=basePath%>t_goods/toT_goodsCurd?oplx=view&id="+item.goods_id+"&time="+Math.random()+"' class='text-danger'>&nbsp;&nbsp;<span class='glyphicon glyphicon-search' style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
		//str+="<a href='<%=basePath%>t_goods/toT_jf_goodsCurd?oplx=edit&id="+item.goods_id+"&time="+Math.random()+"' class='text-danger' alt='修改商品显示楼层位置' >&nbsp;&nbsp;<span class='icon-pencil'  style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
		//str+="<a href='javascript:del("+item.goods_id+")' class='text-danger'>&nbsp;&nbsp;<span class='icon-remove' style='color:rgb(0, 128, 255)'></span></a>&nbsp;&nbsp;";
		//str+="</td>";
		str+="</tr>";
		$("#grid_body").append(str);
	});//end each data;

	//2、分业处理
	var element = $("#grid_paging");
	if(data.totalCount>0){
		    //第二种处理分页方案，直接生成分页html内容，然后.html()到目标对象；
	        var pageHtml ="";
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.firstIndex+')">首页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.previousIndex+')">上一页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " >当前第  '+data.currentPageNo+' 页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.nextIndex+')">下一页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.lastIndex+')">尾页</button></li>';
			element.html(pageHtml);
		}else{
			element.html("");
		}
    })//end getJSON;
}



</script>
